package com.bjc.core.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.bjc.base.core.BaseServiceImpl;
import com.bjc.base.core.IBaseDao;
import com.bjc.core.bean.request.DimensionItemReqVO;
import com.bjc.core.bean.response.DimensionItemVO;
import com.bjc.core.dao.IDimensionItemDao;
import com.bjc.core.dao.IDimensionItemDataDao;
import com.bjc.core.service.IDimensionItemService;

/**
 * 维度Item业务实现
 * 
 * @author 许自辉
 * @date 2017年8月17日 下午3:35:08
 */
@Service
public class DimensionItemImpl extends BaseServiceImpl<DimensionItemReqVO, DimensionItemVO>
		implements IDimensionItemService {

	private IDimensionItemDao dimensionItemDao;
	
	@Autowired
	private IDimensionItemDataDao dimensionItemDataDao;

	@Autowired
	@Override
	public void setBaseDao(IBaseDao<DimensionItemReqVO, DimensionItemVO> baseDao) {
		this.baseDao = baseDao;
		this.dimensionItemDao = (IDimensionItemDao) baseDao;
	}
	
	@Override
	public List<DimensionItemVO> getNoRoleList(DimensionItemReqVO reqVO){
		return dimensionItemDao.getNoRoleList(reqVO);
	}

	@Override
	public int insert(DimensionItemReqVO record) {
		DimensionItemReqVO itemReqVO = new DimensionItemReqVO();
		itemReqVO.setDimensionId(record.getDimensionId());
		itemReqVO.setCode(record.getCode());
		List<DimensionItemVO> list = dimensionItemDao.getList(itemReqVO);
		if (CollectionUtils.isEmpty(list)) {
			return super.insert(record);
		}
		return -1;
	}
	
	@Override
	public int update(DimensionItemReqVO record) {
		DimensionItemReqVO reqvo = new DimensionItemReqVO();
		reqvo.setNotId(record.getId());
		reqvo.setDimensionId(record.getDimensionId());
		reqvo.setCode(record.getCode());
		DimensionItemVO itemVO = dimensionItemDao.get(reqvo);
		if (itemVO == null) {
			return super.update(record);
		}
		return -1;
	}

	@Override
	public int deleteById(int id) {
		dimensionItemDataDao.deleteByDimensionItemId(id);
		return super.deleteById(id);
	}

	
}
